<template>
	<view>
		<view class="input">
			<input type="nickname" placeholder="请输入昵称" @change="getNickname" @confirm='confirminput'
				v-model="inputClearValue" maxlength="7"/>
			<uni-icons @click="clearinputvalue" v-if="showClearIcon" type="clear" size="20" color="#E5E5E5"></uni-icons>
		</view>
		<view class="footerbtn">
			<view class="cont" @click="bc">
				<view class="btn" :class="showClearIcon?'':'absbtn'">
					保存
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
	UserInfoUpdate
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				inputClearValue: '',
				showClearIcon: false
			};
		},
		watch: {
			inputClearValue(oldval, newval) {
				if (this.inputClearValue != '') {
					this.showClearIcon = true;
				} else {
					this.showClearIcon = false;
				}
			}
		},
		onLoad(option) {
			this.inputClearValue = option.name
		},
		methods: {
			bc(){
				if(!this.showClearIcon){
					return
				}
				UserInfoUpdate({
					nickName:this.inputClearValue
				}).then(res=>{
					console.log(res);
					uni.showToast({
						icon:'none',
						title:'昵称已修改'
					})
					setTimeout(()=>{
						uni.navigateBack()
					},500)
				})
			},
			confirminput(e) {
				this.inputClearValue = e.detail.value
			},
			clearinputvalue() {
				this.inputClearValue = ''
				this.showClearIcon = false;
			},
			getNickname(e) {
				console.log(e.detail.value);
			}
		}
	}
</script>

<style lang="scss">
	.input {
		width: 670rpx;
		height: 100rpx;
		background: #FBFBFB;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto;
		display: flex;
		align-items: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #000000;
		padding: 0rpx 20rpx;
		box-sizing: border-box;

		input {
			flex: 1;
		}
	}

	.footerbtn {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		position: fixed;
		bottom: 0%;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.cont {
			display: flex;
			padding: 10rpx 20rpx;
			height: 120rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			align-items: center;
			justify-content: center;
			.btn {
				width: 670rpx;
				height: 100rpx;
				background: #000000;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				color: #FFFFFF;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 100rpx;
				text-align: center;
			}
			.absbtn{
				background: #808080;
			}
		}
	}
</style>